<?php

use yii\db\Migration;

class m240417_014729_diandi_hotel_coupon extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%diandi_hotel_coupon}}', [
            'id' => "int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '卡券id'",
            'bloc_id' => "int(11) NULL COMMENT '公司ID'",
            'store_id' => "int(11) NULL COMMENT '商户ID'",
            'create_time' => "datetime NULL",
            'update_time' => "datetime NULL",
            'name' => "varchar(100) NOT NULL COMMENT '卡券名称'",
            'explain' => "varchar(255) NULL COMMENT '卡券说明'",
            'type' => "smallint(6) NULL COMMENT '卡券类型  1：代金券 2：折扣券 '",
            'price' => "decimal(10,2) NULL COMMENT '卡券价格'",
            'use_start' => "datetime NULL COMMENT '时间限制-开始时间'",
            'use_end' => "datetime NULL COMMENT '时间限制-结束时间'",
            'enable_start' => "datetime NULL COMMENT '有效期开始时间'",
            'enable_end' => "datetime NULL COMMENT '有效期结束时间'",
            'inventory' => "int(11) NULL COMMENT '库存'",
            'use_num' => "smallint(6) NULL COMMENT '已使用数量'",
            'max_time' => "varchar(100) NULL COMMENT '消费时长'",
            'enable_store' => "varchar(100) NULL COMMENT '适用店铺'",
            'enable_week' => "varchar(255) NULL COMMENT '适用星期(分别对应1~7）'",
            'third_party' => "varchar(100) NULL COMMENT '第三方编号'",
            'all_num' => "int(11) NULL COMMENT '总发放量'",
            'max_num' => "int(11) NULL COMMENT '最多可购买数量'",
            'background' => "varchar(255) NULL COMMENT '卡券背景图'",
            'cash' => "decimal(10,2) NULL COMMENT '代金券金额'",
            'min_order_price' => "decimal(10,2) NULL COMMENT '使用最小限额'",
            'discount' => "float(6,1) NULL COMMENT '折扣券折扣'",
            'coupon_img' => "varchar(255) NULL COMMENT '卡券图片'",
            'use_hourse' => "varchar(255) NULL COMMENT '使用房间'",
            'num_sort' => "int(11) unsigned NULL DEFAULT '0' COMMENT '排序'",
            'meal_type' => "int(11) NULL COMMENT '默认套餐类型'",
            'hotel_id' => "int(11) NULL COMMENT '酒店id'",
            'room_id' => "int(11) NULL COMMENT '房间/单位id'",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='优惠券主表'");
        
        /* 索引设置 */
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%diandi_hotel_coupon}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

